<template>
  <div class="app-container">

    <!-- 表头 查询与新增 -->
    <el-row>
      <el-col :span="24">
        <div class="filter-container">
          <el-input placeholder="订单号" v-model="listQuery.orderId" style="width: 200px;" class="filter-item"
                    @keyup.enter.native="handleFilter"/>
          <el-input placeholder="用户名称" v-model="listQuery.userName" style="width: 200px;" class="filter-item"
                    @keyup.enter.native="handleFilter"/>
          <el-select v-model="listQuery.orderStatus" placeholder="订单状态" clearable class="filter-item"
                     style="width: 150px"
                     @change="handleFilter">
            <el-option v-for="(value, key) in statusOptions" :key="key" :label="value" :value="key"/>
          </el-select>
          <el-date-picker
            class="filter-item"
            v-model="buyTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd">
          </el-date-picker>
          <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索
          </el-button>
          <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-circle-plus-outline"
                     @click="exportReport">导出订单
          </el-button>
          <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-circle-plus-outline"
                     @click="deleteCloseOrder" >清空关闭订单
          </el-button>
          <!--<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-circle-plus-outline" @click="handleCreate">新增</el-button>-->
        </div>
      </el-col>
    </el-row>

    <!-- 表格list -->
    <el-row>
      <el-col :span="24" :gutter="24">
        <el-table
          v-loading="listLoading"
          :key="tableKey"
          :data="list"
          element-loading-text="Loading"
          border
          fit
          :height="tableHeight"
          style="width: 100%;"
          highlight-current-row>
          <el-table-column align="center" label="序号" width="80">
            <template slot-scope="scope">
              {{ scope.$index }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="订单ID" show-overflow-tooltip min-width="20%" align="center">
            <template slot-scope="scope">
              {{ scope.row.orderId }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="用户名称" show-overflow-tooltip min-width="20%" align="center">
            <template slot-scope="scope">
              {{ scope.row.userName }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="用户手机" show-overflow-tooltip min-width="20%" align="center">
            <template slot-scope="scope">
              {{ scope.row.phone }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="门店名称" show-overflow-tooltip min-width="20%" align="center">
            <template slot-scope="scope">
              {{ scope.row.shopName }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="门店电话" show-overflow-tooltip min-width="20%" align="center">
            <template slot-scope="scope">
              {{ scope.row.shopTel }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip class-name="status-col" label="预定时间" min-width="35%" align="center">
            <template slot-scope="scope">
              <i class="el-icon-time"/>
              <span>{{ scope.row.orderTime | timeFilter}}</span>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip class-name="status-col" label="完成时间" min-width="20%" align="center">
            <template slot-scope="scope">
              <i class="el-icon-time"/>
              <span>{{ scope.row.okTime | timeFilter}}</span>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="订单状态" show-overflow-tooltip min-width="20%" align="center">
            <!--<template slot-scope="scope">
              {{ scope.row.orderStatus }}
            </template>-->
            <template slot-scope="scope">
              <el-tag :type="scope.row.orderStatus | statusFilter">{{ scope.row.orderStatus | validFilter}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="支付方式" show-overflow-tooltip min-width="20%" align="center">
            <!-- <template slot-scope="scope">
               {{ scope.row.payType }}
             </template>-->
            <template slot-scope="scope">
              <el-tag :type="scope.row.payType | statusFilter">{{ scope.row.payType | payFilter}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip label="订单金额" show-overflow-tooltip min-width="20%" align="center">
            <template slot-scope="scope">
              {{ scope.row.money }}
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip class-name="status-col" label="创建时间" min-width="20%" align="center">
            <template slot-scope="scope">
              <i class="el-icon-time"/>
              <span>{{ scope.row.createdTime | timeFilter}}</span>
            </template>
          </el-table-column>
          <!--<el-table-column show-overflow-tooltip class-name="status-col" label="修改时间" style="width: 10%" align="center">
            <template slot-scope="scope">
              <i class="el-icon-time"/>
              <span>{{ scope.row.modifiedTime | timeFilter}}</span>
            </template>
          </el-table-column>-->
          <el-table-column show-overflow-tooltip label="备注" show-overflow-tooltip min-width="12%" align="center">
            <template slot-scope="scope">
              {{ scope.row.remark }}
            </template>
          </el-table-column>
          <el-table-column label="退款操作" align="center" fixed="right" width="86" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" v-if="scope.row.orderStatus == 2" type="danger" @click="cancelOrder(scope.row)">
                取消订单
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="导出操作" align="center" fixed="right" width="86" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" v-if="scope.row.orderStatus == 4 || scope.row.orderStatus == 2" type="warning"
                         @click="exportWord(scope.row)">
                导出订单
              </el-button>
            </template>
          </el-table-column>

          <el-table-column label="拍摄签到" align="center" fixed="right" width="86" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" :disabled="scope.row.photoSign != null && scope.row.photoSign > 0" type="primary" @click="photoSign(scope.row)">
                门店签到
              </el-button>
            </template>
          </el-table-column>

          <el-table-column label="提醒操作" align="center" fixed="right" width="86" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" :disabled="scope.row.remindTimes != null && scope.row.remindTimes > 0" type="primary" @click="sendOrderMag(scope.row)">
                看片提醒
              </el-button>
            </template>
          </el-table-column>

          <el-table-column label="完成操作" align="center" fixed="right" width="86" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" v-if="scope.row.orderStatus == 2" type="warning" @click="successOrder(scope.row)">
                订单完成
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="图片详情" align="center" fixed="right" width="86" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button size="mini" v-if="scope.row.orderStatus == 4 || scope.row.orderStatus == 2" type="success"
                         @click="openOrderImage(scope.row)">
                图片详情
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" fixed="right" width="86" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <!--<el-button size="mini" type="primary" @click="handleUpdate(scope.row)">
                编辑
              </el-button>-->
              <el-button size="mini" type="primary" @click="OpenOrderDetail(scope.row)">
                套餐详情
              </el-button>
              <!-- <el-button size="mini" type="primary" @click="uploadOrderImage(scope.row)">
                 图片上传
               </el-button>-->
              <!--<el-button size="mini" type="danger" @click="handleDelete(scope.row)">-->
              <!--删除-->
              <!--</el-button>-->
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total"
                    :page.sync="listQuery.pageNum"
                    :limit.sync="listQuery.pageSize"
                    layout="total, sizes, prev, pager, next"
                    style="float:right;"
                    @pagination="fetchData"/>
      </el-col>
    </el-row>

    <el-dialog title="订单套餐详情"
               :visible.sync="dialogTableVisible"
               :close-on-click-modal="false"
               width="80%"
               size="large"
               top="1%">
      <el-table
        :key="tableKey"
        :data="orderDetailData"
        element-loading-text="Loading"
        border
        fit
        style="width: 100%;"
        highlight-current-row>
        <el-table-column align="center" label="序号" width="80">
          <template slot-scope="scope">
            {{ scope.$index }}
          </template>
        </el-table-column>
        <!--<el-table-column show-overflow-tooltip label="订单细表ID" show-overflow-tooltip style="width: 10%" align="center">
          <template slot-scope="scope">
            {{ scope.row.detailId }}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="订单ID" show-overflow-tooltip style="width: 10%" align="center">
          <template slot-scope="scope">
            {{ scope.row.orderId }}
          </template>
        </el-table-column>-->
        <!--<el-table-column show-overflow-tooltip label="商品ID" show-overflow-tooltip style="width: 10%" align="center">
          <template slot-scope="scope">
            {{ scope.row.productId }}
          </template>
        </el-table-column>-->
        <el-table-column show-overflow-tooltip label="商品数量" show-overflow-tooltip style="width: 10%" align="center">
          <template slot-scope="scope">
            {{ scope.row.productCount }}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="拍照人数" show-overflow-tooltip style="width: 10%" align="center">
          <template slot-scope="scope">
            {{ scope.row.peopleCount }}
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="产品名称" show-overflow-tooltip style="width: 10%" align="center">
          <template slot-scope="scope">
            {{ scope.row.productName }}
          </template>
        </el-table-column>
        <!--<el-table-column show-overflow-tooltip label="产品图片" show-overflow-tooltip style="width: 10%" align="center">
          <template slot-scope="scope">
            {{scope.row.productImg}}
          </template>
        </el-table-column>-->
        <el-table-column show-overflow-tooltip label="基准价格" show-overflow-tooltip style="width: 10%" align="center">
          <template slot-scope="scope">
            {{ scope.row.productPrice }}
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 编辑弹窗 -->
    <el-dialog
      :title="textMap[dialogStatus]"
      :visible.sync="dialogFormVisible">
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="temp"
        label-position="right"
        label-width="100px"
        style="">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="订单ID" label-width="105px" prop="orderId">
              <el-input v-model="temp.orderId" :disabled="dialogStatus === 'update'"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="用户ID" label-width="105px" prop="userId">
              <el-input v-model="temp.userId"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="门店ID" label-width="105px" prop="shopId">
              <el-input v-model="temp.shopId"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="门店名称" label-width="105px" prop="shopName">
              <el-input v-model="temp.shopName"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="门店电话" label-width="105px" prop="shopTel">
              <el-input v-model="temp.shopTel"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item class="el-row-height"
                          label="预定时间"
                          prop="orderTime">
              <el-date-picker class="el-select-style"
                              v-model="temp.orderTime"
                              align="right"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item class="el-row-height"
                          label="完成时间"
                          prop="orderTime">
              <el-date-picker class="el-select-style"
                              v-model="temp.okTime"
                              align="right"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="订单状态" label-width="105px" prop="orderStatus">
              <el-input v-model="temp.orderStatus"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支付方式" label-width="105px" prop="payType">
              <el-input v-model="temp.payType"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="订单金额" label-width="105px" prop="money">
              <el-input v-model="temp.money"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注信息" label-width="105px" prop="remark">
              <el-input v-model="temp.remark"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">确认</el-button>
        <el-button @click="dialogFormVisible = false">取消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import SxOrderRecordApi from '@/api/manage/SxOrderRecordApi';
  import SxOrderImgApi from '@/api/manage/SxOrderImgApi';
  import waves from '@/directive/waves'; // Waves directive
  import SxOrderRecordDetailApi from '@/api/manage/SxOrderRecordDetailApi';
  import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  import Tinymce from '@/components/Tinymce'

  export default {
    directives: {waves},
    components: {Pagination, Tinymce},
    filters: {
      statusFilter(status) {
        const statusMap = {
          0: 'success',
          1: 'gray',
          2: 'danger',
          3: 'info',
          4: 'success',
        }
        return statusMap[status]
      },
      validFilter(status) {
        const statusMap = {
          1: '进行中',
          2: '已付款',
          3: '已关闭',
          4: '已完成',
        }
        return statusMap[status]
      },

      payFilter(status) {
        const statusMap = {
          0: '支付宝',
          1: '微信'
        }
        return statusMap[status]
      },
      timeFilter(time) {
        if (time) {
          return new Date(time).Format('yyyy-MM-dd hh:mm:ss')
        } else {
          return ''
        }
      },
    },
    data() {
      return {
        tableKey: 0,//表格key值
        list: null, //表格对象
        listLoading: true, //表格加载框
        total: 0, //分页总数
        dialogImageVisible: false, //图片上传显示
        orderDetailData: [], //订单细表数据
        fileList: [
          /*{
            name: '',
            url: ''
          }*/
        ],//上传订单照片数组
        uploadUrl: process.env.BASE_API + '/file/upload', //订单图片上传
        exportWordUrl: process.env.BASE_API + 'sxOrderRecord/exportOrderWord', //订单服务导出
        exportUrl: process.env.BASE_API + 'sxOrderRecord/exportExcel', //订单图片上传
        dialogTableVisible: false, //订单细表详情展示
        tableHeight: window.innerHeight - 220, //表格高度
        listQuery: { //表格查询对象
          pageNum: 1,
          pageSize: 10,
          query: '',
          orderStatus: '',
          payType: '1',
          orderId: '',
          shopId: '',
          userName: ''
        },
        buyTime: '',
        temp: {}, //编辑框临时变量
        orderImage: {
          'orderId': '',
          'details': '',
          'imageType': '1'
        }, //上传框临时变量
        statusOptions: { //有效无效下拉框
          '1': '进行中',
          '2': '已付款',
          '3': '已关闭',
          '4': '已完成'
        },
        photoOptions: [ //图片类型下拉框
          {
            label: '原图',
            value: '1'
          },
          {
            label: '压缩',
            value: '2'
          }],
        dialogFormVisible: false, //编辑框显示
        dialogStatus: '', //编辑框更新插入状态
        textMap: { //编辑框标题
          update: '编辑',
          create: '创建'
        },
        detailQuery: {
          orderId: '',
        },
        imgDetailArr: [],//图片数组
        editModal: false,
        rules: { //编辑框校验规则
          orderId: [{required: true, message: '请输入订单ID', trigger: 'change'}],
          shopName: [{required: true, message: '请输入门店名称', trigger: 'change'}],
          shopTel: [{required: true, message: '请输入门店电话', trigger: 'change'}],
          orderStatus: [{required: true, message: '请输入订单状态', trigger: 'change'}],
          payType: [{required: true, message: '请输入支付方式', trigger: 'change'}],
          money: [{required: true, message: '请输入订单金额', trigger: 'change'}],
          remark: [{required: true, message: '请输入备注信息', trigger: 'change'}],
        },
        rulesPhoto: { //图片编辑框校验规则
          imageType: [{required: true, message: '请选择图片类型', trigger: 'change'}],
        }
      }
    },
    computed: {
      validSwitch: {
        // getter
        get: function () {
          return this.temp.validFlag === '1'
        },
        // setter
        set: function (newValue) {
          if (newValue) {
            this.temp.validFlag = '1'
          } else {
            this.temp.validFlag = '0'
          }
        }
      },
      ownShopId() {
        return this.$store.getters.manageShop
      },
    },
    created() {

      console.log(this.$store.getters.manageShop)
      this.listQuery.shopId = this.ownShopId || ''
      this.fetchData()
    },
    methods: {

      /**
       * 订单完成按钮
       */
      successOrder(row) {
        let that = this;
        row = this.$_.assignIn({}, row, {r: Math.random()})
        SxOrderRecordApi.orderSuccess(row).then((res) => {
          that.$message({
            title: '成功',
            message: '订单状态修改为订单完成成功！',
            type: 'success',
            duration: 1000,
            onClose() {
              that.fetchData();
            }
          })
        }).catch(function (error) {
          that.$message({
            title: '失败',
            message: '原图版”和“分享版”图片未完全上传',
            type: 'warning',
            duration: 1000,
            onClose() {
              that.fetchData();
            }
          })
        });

      },

      /**
       * 拍摄签到钮
       */
      photoSign(row) {
        let that = this;
        row = this.$_.assignIn({}, row, {r: Math.random()})
        SxOrderRecordApi.photoSign(row).then((res) => {
          that.$message({
            title: '成功',
            message: '看片门店拍摄签到成功！',
            type: 'success',
            duration: 1000,
            onClose() {
              that.fetchData();
            }
          })
        }).catch(function (error) {
          that.$message({
            title: '失败',
            message: error.data,
            type: 'warning',
            duration: 1000,
            onClose() {
              that.fetchData();
            }
          })
        });

      },

      /**
       * 看片提醒按钮
       */
      sendOrderMag(row) {
        let that = this;
        row = this.$_.assignIn({}, row, {r: Math.random()})
        SxOrderRecordApi.sendOrderSuccess(row).then((res) => {
          that.$message({
            title: '成功',
            message: '看片提醒信息发送成功！',
            type: 'success',
            duration: 1000,
            onClose() {
              that.fetchData();
            }
          })
        }).catch(function (error) {
          that.$message({
            title: '失败',
            message: error.data,
            type: 'warning',
            duration: 1000,
            onClose() {
              that.fetchData();
            }
          })
        });

      },

      /**
       * 导出具体订单服务按钮
       */
      exportWord(row) {
        debugger
        // 创建一个 form
        var form1 = document.createElement("form");
        form1.id = "form1";
        form1.name = "form1";

        // 添加到 body 中
        document.body.appendChild(form1);

        // 创建一个输入
        var input = document.createElement("input");
        // 设置相应参数
        input.type = "text";
        input.name = "query";
        input.value = JSON.stringify(row);

        /*  // 创建一个输入
          var input1 = document.createElement("input");
          // 设置相应参数
          input1.type = "text";
          input1.name = "times";
          if (this.buyTime && this.buyTime.length > 0) {
            input1.value = JSON.stringify(this.buyTime);
          } else {
            input1.value = null;
          }*/

        // 将该输入框插入到 form 中
        form1.appendChild(input);
//        form1.appendChild(input1);


        // form 的提交方式
        form1.method = "POST";
        // form 提交路径
        form1.action = this.exportWordUrl;

        // 对该 form 执行提交
        form1.submit();
        // 删除该 form
        document.body.removeChild(form1);
      },
      /**
       * 导出订单按钮
       */
      exportReport() {

        // 创建一个 form
        var form1 = document.createElement("form");
        form1.id = "form1";
        form1.name = "form1";

        // 添加到 body 中
        document.body.appendChild(form1);

        // 创建一个输入
        var input = document.createElement("input");
        // 设置相应参数
        input.type = "text";
        input.name = "query";
        input.value = this.listQuery.query;

        // 创建一个输入
        var input1 = document.createElement("input");
        // 设置相应参数
        input1.type = "text";
        input1.name = "times";
        if (this.buyTime && this.buyTime.length > 0) {
          input1.value = JSON.stringify(this.buyTime);
        } else {
          input1.value = null;
        }

        // 创建一个输入
        var input2 = document.createElement("input");
        // 设置相应参数
        input2.type = "text";
        input2.name = "payType";
        input2.value = this.listQuery.payType;

        // 将该输入框插入到 form 中
        form1.appendChild(input);
        form1.appendChild(input1);
        form1.appendChild(input2);


        // form 的提交方式
        form1.method = "POST";
        // form 提交路径
        form1.action = this.exportUrl;

        // 对该 form 执行提交
        form1.submit();
        // 删除该 form
        document.body.removeChild(form1);

      },

      cancelOrder(row) {
        let that = this;
        this.$set(row, 'manageFlag', '1')
        SxOrderRecordApi.update(row).then((res) => {

          this.$message({
            title: '成功',
            message: '取消订单成功',
            type: 'success',
            duration: 1000,
            onClose() {
              that.fetchData();
            }
          })
        }).catch((response) => {

          that.$message({
            title: '失败',
            message: response.error,
            type: 'warning',
            duration: 1000,
            onClose() {
              that.fetchData();
            }
          })
        })
      },

      /**
       * 删除关闭状态订单
       */
      deleteCloseOrder() {
        let that = this;
        this.$confirm('此操作清空关闭状态订单, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          SxOrderRecordApi.deleteCloseOrder({}).then(() => {
            this.$notify({
              title: '成功',
              message: '清空关闭状态订单成功',
              type: 'success',
              duration: 1000,
              onClose() {
                that.fetchData();
              }
            })
          });
        });
      },

      /**
       * 打开订单图片
       * */
      openOrderImage(row) {
        let that = this;
        that.fileList = [];
        this.$router.push({name: 'orderImage', params: row})
      },

      /**
       * 获取表格数据
       */
      fetchData() {
        let that = this;
        this.listLoading = true

        if (this.buyTime && this.buyTime.length > 0) {
          this.listQuery.times = JSON.stringify(this.buyTime);
        } else {
          this.listQuery.times = null;
        }
        this.$http.all([SxOrderRecordApi.getPage(this.listQuery)])
          .then(this.$http.spread(function (perms) {
            that.list = perms.rows
            that.total = perms.total
            that.listLoading = false
          }));
      },
      /**
       * 新增弹窗
       */
      handleCreate() {
        this.resetTemp()
        this.dialogStatus = 'create'
        this.dialogFormVisible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].clearValidate()
        })
      },
      /**
       * 清空弹窗内容
       */
      resetTemp() {
        this.temp = {
          orderId: '',
          userId: '',
          shopId: '',
          shopName: '',
          shopTel: '',
          orderTime: '',
          okTime: '',
          orderStatus: '',
          payType: '',
          money: '',
          createdTime: '',
          modifiedTime: '',
          remark: '',
          validFlag: '1'
        }
      },
      /**
       * 确定新增
       */
      createData() {
        let that = this;
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            SxOrderRecordApi.insert(this.temp).then(() => {
              this.dialogFormVisible = false
              this.$notify({
                title: '成功',
                message: '创建成功',
                type: 'success',
                duration: 1000,
                onClose() {
                  that.fetchData();
                }
              })
            })
          }
        })
      },


      /**
       * 打开订单细表详情
       */
      OpenOrderDetail(row) {

        this.detailQuery.orderId = row.orderId;
        let that = this;
        this.dialogTableVisible = true
        this.$http.all([SxOrderRecordDetailApi.findList(this.detailQuery)])
          .then(this.$http.spread(function (perms) {
            that.orderDetailData = perms;
          }));
      },
      /**
       * 编辑弹窗
       */
      handleUpdate(row) {
        this.temp = Object.assign({}, row)
        this.dialogStatus = 'update'
        this.dialogFormVisible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].clearValidate()
        })
      },
      /**
       * 确认编辑
       */
      updateData() {
        let that = this;
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            const tempData = Object.assign({}, this.temp)
            SxOrderRecordApi.update(tempData).then(() => {
              this.dialogFormVisible = false
              this.$notify({
                title: '成功',
                message: '更新成功',
                type: 'success',
                duration: 1000,
                onClose() {
                  that.fetchData();
                }
              })
            })
          }
        })
      },
      /**
       * 删除操作
       */
      handleDelete(row) {
        let that = this;
        SxOrderRecordApi.remove({orderId: row.orderId}).then(() => {
          this.$notify({
            title: '成功',
            message: '删除成功',
            type: 'success',
            duration: 1000,
            onClose() {
              that.fetchData();
            }
          })
        })
      },
      /**
       * 搜索过滤
       */
      handleFilter() {

        this.listQuery.pageNum = 1
        this.fetchData()
      }
    }
  }
</script>
